﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SWS.PIP.CMD
{
	/// <summary>
	/// 页码排序类
	/// </summary>
	class DataGridViewPageComparer: IComparer
	{
		private DataGridViewColumn m_Column;

		public DataGridViewPageComparer(DataGridViewColumn p_Column)
		{
			m_Column = p_Column;
		}

		int IComparer.Compare(Object x, Object y)
		{
			if (m_Column == null) return -1;
			decimal _X;
			decimal _Y;

			bool _XConvert = decimal.TryParse(((DataGridViewRow)x).Cells[m_Column.Name].Value.ToString(), out _X);
			bool _YConvert = decimal.TryParse(((DataGridViewRow)y).Cells[m_Column.Name].Value.ToString(), out _Y);
			int _CompareValue = _X.CompareTo(_Y);

			if (m_Column.HeaderCell.SortGlyphDirection == SortOrder.Descending) return _CompareValue * -1;

			return _CompareValue;
		}
	}
}
